package com.edu.web.servlet;

import com.edu.entity.Comment;
import com.edu.entity.Vehicles;
import com.edu.service.CommentService;
import com.edu.service.VehiclesService;
import com.edu.service.imlp.CommentServiceImpl;
import com.edu.service.imlp.VehiclesServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/carxxServlet")
public class CarxxServlet extends HttpServlet {
    VehiclesService vehiclesService = new VehiclesServiceImpl();
    CommentService commentService = new CommentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取车辆id
        int id = Integer.parseInt(req.getParameter("id"));
        //车辆的信息
        Vehicles vehicles = vehiclesService.queryById(id);
        req.setAttribute("vehicles" ,vehicles);
        //车的评论
        List<Comment> comments = commentService.querCommentByCarId(id);
        req.setAttribute("comments" ,comments);
        req.getRequestDispatcher("/u/page/carxx.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
